package com.suning.app.snpaasadmin.operation;

import com.suning.app.snpaasadmin.dao.CfClusterCtrlmachineMapper;
import com.suning.app.snpaasadmin.pojo.CfClusterCtrlmachine;
import com.suning.app.snpaasadmin.pojo.CfClusterCtrlmachineExample;
import com.suning.app.snpaasadmin.util.Constants;
import com.suning.app.snpaasadmin.util.DbContextHolder;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CfClusterCtrlmachineDBOperation {
    
    @Autowired
    private CfClusterCtrlmachineMapper ctrlmachineMapper;
    
	public void insert(CfClusterCtrlmachine cm) throws Exception{
	    DbContextHolder.setDbType(Constants.DATASOURCE_ADMIN);
	    ctrlmachineMapper.insertSelective(cm);
	}
	
	public boolean selectIpUser(String host, String userName) throws Exception{
	    DbContextHolder.setDbType(Constants.DATASOURCE_ADMIN);
	    CfClusterCtrlmachineExample example = new CfClusterCtrlmachineExample();
        example.createCriteria().andHostIpEqualTo(host).andUserNameEqualTo(userName);
        List<CfClusterCtrlmachine> ctrlmachines = ctrlmachineMapper.selectByExample(example);
        if(ctrlmachines != null && ctrlmachines.size()>0){
            return false;
        }
	    return true;
	}

}
